<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="仓库编码" prop="stockCode">
        <el-input
          v-model="queryParams.stockCode"
          placeholder="请输入仓库编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库名称" prop="stockName">
        <el-input
          v-model="queryParams.stockName"
          placeholder="请输入仓库名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库类型" prop="stockType">
        <el-select v-model="queryParams.stockType" placeholder="请选择仓库类型" clearable>
          <el-option
            v-for="dict in dict.type.stock_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="仓库类别" prop="stockType2">
        <el-select v-model="queryParams.stockType2" placeholder="请选择仓库类别" clearable>
          <el-option
            v-for="dict in dict.type.stock_type2"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="智能类别" prop="stockType3">
        <el-select v-model="queryParams.stockType3" placeholder="请选择智能类别" clearable>
          <el-option
            v-for="dict in dict.type.stock_type3"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['base:warehouseinfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['base:warehouseinfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['base:warehouseinfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['base:warehouseinfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="warehouseinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--
      <el-table-column label="主键" align="center" prop="id" />
-->
      <el-table-column label="公司代码" align="center" prop="tenantId" />
      <el-table-column label="仓库编码" align="center" prop="stockCode" />
      <el-table-column label="仓库名称" width="120" align="center" prop="stockName" />
      <el-table-column label="仓库权属" align="center" prop="stockQuanshu" />
      <el-table-column label="仓库类型" align="center" prop="stockType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stock_type" :value="scope.row.stockType"/>
        </template>
      </el-table-column>
      <el-table-column label="仓库类别" align="center" prop="stockType2">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stock_type2" :value="scope.row.stockType2"/>
        </template>
      </el-table-column>
      <el-table-column label="智能类别" width="120" align="center" prop="stockType3">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stock_type3" :value="scope.row.stockType3"/>
        </template>
      </el-table-column>
      <el-table-column label="管理部门代码" align="center" prop="deptId" />
      <el-table-column label="管理部门名称" width="120"  align="center" prop="deptName" />
      <el-table-column label="物流代码" align="center" prop="wuliuId" />
      <el-table-column label="物流名称" width="120" align="center" prop="wuliuName" />
      <el-table-column label="面积" align="center" prop="mianji" />
      <el-table-column label="单价" align="center" prop="unitPrice" />
      <el-table-column label="日租金额" align="center" prop="rizuPrice" />
      <el-table-column label="月租金额" align="center" prop="yuezuPrice" />
      <el-table-column label="年租金额" align="center" prop="nianzuPrice" />
      <el-table-column label="操作单位代码" align="center" prop="caozuodanweiId" />
      <el-table-column label="操作人员工号" align="center" prop="caozuorenyuanId" />
      <el-table-column label="时出入能力" align="center" prop="scrnl" />
      <el-table-column label="时输送能力" align="center" prop="sssnl" />
      <el-table-column label="综合能力" align="center" prop="zhnl" />
      <el-table-column label="收货管理" align="center" prop="shState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stock_state" :value="scope.row.shState"/>
        </template>
      </el-table-column>
      <el-table-column label="上架管理" align="center" prop="sjState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stock_state" :value="scope.row.sjState"/>
        </template>
      </el-table-column>
      <el-table-column label="下架管理" align="center" prop="xjState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stock_state" :value="scope.row.xjState"/>
        </template>
      </el-table-column>
      <el-table-column label="出库管理"  align="center" prop="ckState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stock_state" :value="scope.row.ckState"/>
        </template>
      </el-table-column>
      <el-table-column label="调拨管理" align="center" prop="dbState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stock_state" :value="scope.row.dbState"/>
        </template>
      </el-table-column>
      <el-table-column label="卸车位" align="center" prop="xcw" />
      <el-table-column label="装车位" align="center" prop="zcw" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" fixed="right" width="130"  align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['base:warehouseinfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['base:warehouseinfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改仓库管理对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
       <!-- <el-form-item label="公司代码" prop="tenantId">
          <el-input v-model="form.tenantId" placeholder="请输入公司代码" />
        </el-form-item>-->
        <!--  <el-form-item label="公司名称" prop="tenantId">
            <el-select v-model="form.tenantId" placeholder="请选择公司名称">
              <el-option
                v-for="item in gcCodeList"
                :key="item.jtdm"
                :label="item.jtmc"
                :value="item.jtdm">
                <span style="float: left">{{ item.jtmc }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.jtdm }}</span>
              </el-option>
            </el-select>
          </el-form-item>-->
      <!--  <el-form-item label="管理部门代码" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入管理部门代码" />
        </el-form-item>
        <el-form-item label="管理部门名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入管理部门名称" />
        </el-form-item>-->
        <el-form-item label="管理部门" prop="deptId">
          <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择管理部门" />
        </el-form-item>
        <el-form-item label="物流代码" prop="wuliuId">
          <el-input v-model="form.wuliuId" placeholder="请输入物流代码" />
        </el-form-item>
        <el-form-item label="物流名称" prop="wuliuName">
          <el-input v-model="form.wuliuName" placeholder="请输入物流名称" />
        </el-form-item>
        <el-form-item label="仓库编码" prop="stockCode">
          <el-input v-model="form.stockCode" placeholder="请输入仓库编码" />
        </el-form-item>
        <el-form-item label="仓库名称" prop="stockName">
          <el-input v-model="form.stockName" placeholder="请输入仓库名称" />
        </el-form-item>
        <el-form-item label="仓库权属" prop="stockQuanshu">
          <el-input v-model="form.stockQuanshu" placeholder="请输入仓库权属" />
        </el-form-item>
        <el-form-item label="仓库类型" prop="stockType">
          <el-select v-model="form.stockType" placeholder="请选择仓库类型">
            <el-option
              v-for="dict in dict.type.stock_type"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="仓库类别" prop="stockType2">
          <el-select v-model="form.stockType2" placeholder="请选择仓库类别">
            <el-option
              v-for="dict in dict.type.stock_type2"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="智能类别" prop="stockType3">
          <el-select v-model="form.stockType3" placeholder="请选择智能类别">
            <el-option
              v-for="dict in dict.type.stock_type3"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="停用标识" prop="stopFlag">
          <el-input v-model="form.stopFlag" placeholder="请输入停用标识" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="面积" prop="mianji">
          <el-input v-model="form.mianji" placeholder="请输入面积" />
        </el-form-item>
        <el-form-item label="单价" prop="unitPrice">
          <el-input v-model="form.unitPrice" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="日租金额" prop="rizuPrice">
          <el-input v-model="form.rizuPrice" placeholder="请输入日租金额" />
        </el-form-item>
        <el-form-item label="月租金额" prop="yuezuPrice">
          <el-input v-model="form.yuezuPrice" placeholder="请输入月租金额" />
        </el-form-item>
        <el-form-item label="年租金额" prop="nianzuPrice">
          <el-input v-model="form.nianzuPrice" placeholder="请输入年租金额" />
        </el-form-item>
        <el-form-item label="操作单位代码" prop="caozuodanweiId">
          <el-input v-model="form.caozuodanweiId" placeholder="请输入操作单位代码" />
        </el-form-item>
        <el-form-item label="操作人员工号" prop="caozuorenyuanId">
          <el-input v-model="form.caozuorenyuanId" placeholder="请输入操作人员工号" />
        </el-form-item>
        <el-form-item label="时出入能力" prop="scrnl">
          <el-input v-model="form.scrnl" placeholder="请输入时出入能力" />
        </el-form-item>
        <el-form-item label="时输送能力" prop="sssnl">
          <el-input v-model="form.sssnl" placeholder="请输入时输送能力" />
        </el-form-item>
        <el-form-item label="综合能力" prop="zhnl">
          <el-input v-model="form.zhnl" placeholder="请输入综合能力" />
        </el-form-item>
        <el-form-item label="收货管理" prop="shState">
          <el-select v-model="form.shState" placeholder="请选择收货管理">
            <el-option
              v-for="dict in dict.type.stock_state"
              :key="dict.value"
              :label="dict.label" :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="上架管理" prop="sjState">
          <el-select v-model="form.sjState" placeholder="请选择上架管理">
            <el-option
              v-for="dict in dict.type.stock_state"
              :key="dict.value"
              :label="dict.label" :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="下架管理" prop="xjState">
          <el-select v-model="form.xjState" placeholder="请选择下架管理">
            <el-option
              v-for="dict in dict.type.stock_state"
              :key="dict.value"
              :label="dict.label" :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出库管理" prop="ckState">
          <el-select v-model="form.ckState" placeholder="请选择出库管理">
            <el-option
              v-for="dict in dict.type.stock_state"
              :key="dict.value"
              :label="dict.label" :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="调拨管理" prop="dbState">
          <el-select v-model="form.dbState" placeholder="请选择调拨管理">
            <el-option
              v-for="dict in dict.type.stock_state"
              :key="dict.value"
              :label="dict.label" :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="卸车位" prop="xcw">
          <el-input v-model="form.xcw" placeholder="请输入卸车位" />
        </el-form-item>
        <el-form-item label="装车位" prop="zcw">
          <el-input v-model="form.zcw" placeholder="请输入装车位" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWarehouseinfo, getWarehouseinfo, delWarehouseinfo, addWarehouseinfo, updateWarehouseinfo } from "@/api/base/warehouseinfo";
import {listAllOrgManage} from "@/api/hr/orgManage";
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Warehouseinfo",
  dicts: ['stock_state', 'stock_type', 'stock_type3', 'stock_type2'],
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 仓库管理表格数据
      warehouseinfoList: [],
      // 部门树选项
      deptOptions: undefined,
      gcCodeList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stockCode: null,
        stockName: null,
        stockType: null,
        stockType2: null,
        stockType3: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        stockCode: [
          { required: true, message: "仓库编码不能为空", trigger: "blur" }
        ],
        stockName: [
          { required: true, message: "仓库名称不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "管理部门不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getTreeselect();
    listAllOrgManage().then(response => {
      this.gcCodeList = response.rows;
    });
  },
  methods: {
    /** 查询仓库管理列表 */
    getList() {
      this.loading = true;
      listWarehouseinfo(this.queryParams).then(response => {
        this.warehouseinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tenantId: null,
        deptId: null,
        deptName: null,
        wuliuId: null,
        wuliuName: null,
        stockCode: null,
        stockName: null,
        stockQuanshu: null,
        stockType: null,
        stockType2: null,
        stockType3: null,
        stopFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        mianji: null,
        unitPrice: null,
        rizuPrice: null,
        yuezuPrice: null,
        nianzuPrice: null,
        caozuodanweiId: null,
        caozuorenyuanId: null,
        scrnl: null,
        sssnl: null,
        zhnl: null,
        shState: null,
        sjState: null,
        xjState: null,
        ckState: null,
        dbState: null,
        xcw: null,
        zcw: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加仓库管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWarehouseinfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改仓库管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWarehouseinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWarehouseinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除仓库管理编号为"' + ids + '"的数据项？').then(function() {
        return delWarehouseinfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('base/warehouseinfo/export', {
        ...this.queryParams
      }, `warehouseinfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
